package problema036;

public class DoubleBasePalindromes {

	public static void main(String[] args){
		System.out.println(doubleBase());
	}
	
	public static long doubleBase(){
		long res = 0;
		for(int i = 1; i < 1000000; i++){
			if(esPalindromo10(i) && esPalindromo2(i)){
				res += i;
			}
		}
		return res;
	}
	
	public static boolean esPalindromo10(long num){
		long reverso = 0, act = 0, orig = num;
		while (num > 0) {
		      act = num % 10;
		      reverso = reverso * 10 + act;
		      num = num / 10;
		 }
		return orig == reverso;
	}
	
	public static boolean esPalindromo2(long num){
		String ns = Long.toBinaryString(num), nr = "";
		char c;
		for(int i = ns.length()-1; i >= 0; i--){
			c = ns.charAt(i);
			nr = nr + c;
		}
		return ns.equals(nr);
	}
	
}
